package com.docmgmt.mvp.mapper;

import com.docmgmt.mvp.entity.CommentEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 文件评论表 Mapper 接口
 * </p>
 *
 * @author Dora
 */
@Mapper
public interface CommentMapper extends BaseMapper<CommentEntity> {

    /**
     * Query file comments (not deleted)
     *
     * @param fileId File ID
     * @return Comment list
     */
    @Select("SELECT * FROM doc_comment WHERE file_id = #{fileId} " +
            "AND is_deleted = 0 ORDER BY created_at ASC")
    List<CommentEntity> listByFileId(@Param("fileId") Long fileId);

    /**
     * Query top-level comments
     *
     * @param fileId File ID
     * @return Top-level comment list
     */
    @Select("SELECT * FROM doc_comment WHERE file_id = #{fileId} " +
            "AND parent_id = 0 AND is_deleted = 0 ORDER BY created_at ASC")
    List<CommentEntity> listTopLevelByFileId(@Param("fileId") Long fileId);

    /**
     * Query child comments
     *
     * @param parentId Parent comment ID
     * @return Child comment list
     */
    @Select("SELECT * FROM doc_comment WHERE parent_id = #{parentId} " +
            "AND is_deleted = 0 ORDER BY created_at ASC")
    List<CommentEntity> listByParentId(@Param("parentId") Long parentId);
}
